package cn.tedu.health.controller;

import cn.tedu.health.pojo.entity.Visualizations;
import cn.tedu.health.response.JsonResult;
import cn.tedu.health.service.IVisualizationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/api")
public class VisualizationsController {

    @Autowired
    private IVisualizationsService visualizationsService;

    @PostMapping("/visualizations")
    public JsonResult createVisualization(@RequestBody Visualizations visualizations) {
        visualizationsService.createVisualization(visualizations);
        return JsonResult.ok();
    }

    @GetMapping("/visualizations")
    public JsonResult getVisualization(@RequestParam Long userId, @RequestParam LocalDate date) {
        Visualizations visualizations = visualizationsService.getVisualization(userId, date);
        return JsonResult.ok(visualizations);
    }

    @GetMapping("/visualizations/{userId}")
    public JsonResult getVisualizationsByUserId(@PathVariable Long userId) {
        List<Visualizations> visualizationsList = visualizationsService.getVisualizationsByUserId(userId);
        return JsonResult.ok(visualizationsList);
    }
}
